define(function (require, exports, module) {
    'use strict';
    
    var rk = require('rk');
    require('./controllers/usersettingEduCtrl');
    require('./controllers/usersettingPwdCtrl');
    require('./controllers/usersettingWorkCtrl');
    require('./controllers/usersettingIconCtrl');
    require('./controllers/usersettingPassportCtrl');
    require('./controllers/usersettingSubscribeCtrl');
    require('./controllers/usersettingProfileCtrl');
    require('./controllers/usersettingLangCtrl');
    return {
        init: function () {
            var rkPanel = rk.showPageView('rk-panel');

            var tabMap = {
                work: 'usersettingWorkCtrl',
                edu: 'usersettingEduCtrl',
                profile: 'usersettingProfileCtrl',
                icon: 'usersettingIconCtrl',
                passwd: 'usersettingPwdCtrl',
                passport: 'usersettingPassportCtrl',
                subscribe: 'usersettingSubscribeCtrl',
                lang: 'usersettingLangCtrl'
            };
            var data = {};
            data.wanxue = WANXUE;
            rkPanel.html(rk.templateText(require('page/tmpl/usersetting/tpl_user_setting_index.tpl'),data));
            rk.setTitle(rk.i18n('USERSET_USERSETTING'));
            var $profilePanel = $('.profile-panel');
            //$profilePanel.beScroll();
            var $profileContent = $('.profile-content >.profile-content-inner');
            $profileContent.beScroll();
            $profilePanel.on('click', '.profile-subnav li', function (event) {
                var $this = $(this);
                $profilePanel.find('.profile-subnav li.active').removeClass('active') && ($this.hasClass('active') || $this.addClass('active'))

                var act = $this.attr('act');

                if (tabMap[act]) {
                    $profileContent.data(act) && $profileContent.off() && $profileContent[tabMap[act]]('destroy');
                    if(act !== 'icon'){
                        $profileContent[tabMap[act]]({selector: $this}).data(act, true);
                    }else{
                        $profileContent[tabMap[act]]({selector: $this,success: function(data){
                            $('#pageleft').pageLeftCtrl('updateUserPic', data.picUrl.smallIcon);
                        }}).data(act, true);
                    }

                }
                return false;

            });

            $profilePanel.find('.profile-subnav li:eq(0)').trigger('click');
        }
    }

});
